import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

/**
 * I love IntelliJ :)
 * Author: shou1dwe
 * Time: 1/5/13 1:33 AM
 */
public class UDPClient {
    private static int PACKET_SIZE = 1024;

    public static void main(String args[]) throws IOException {

        DatagramSocket s = new DatagramSocket();
        Scanner scanner = new Scanner(System.in);
        byte inBuffer[] = new byte[PACKET_SIZE];

        while (true) {
            String input = scanner.next();
            byte outBuffer[] = input.getBytes();

            InetAddress address = InetAddress.getByName("localhost");
            DatagramPacket outPkt = new DatagramPacket(outBuffer, outBuffer.length, address, 9000);
            s.send(outPkt);

            DatagramPacket inPacket = new DatagramPacket(inBuffer, inBuffer.length);
            s.receive(inPacket);

            String reply = new String(inPacket.getData(), 0, inPacket.getLength());
            System.out.println(reply);
        }
    }
}
